<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
test(function(t) {

    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');
    var canvasWidth = 100;
    var canvasHeight = 50;
    canvas.setWidth = canvasWidth;
    canvas.setHeight = canvasHeight;
    
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);
    ctx.font = '35px Arial, sans-serif';
    
    ctx.fillStyle = '#f00';
    ctx.fillText("fail fail fail fail fail", 5, 35, 0);
    
    var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
    var w = imageData.width, h = imageData.height, d = imageData.data;
    var pixelsCheck = true;
    loopMain1:
    for (var i = 0; i < h; ++i) {
        for (var j = 0; j < w; ++j) {
            if (d[4 * (w * i + j) + 0] != 0) pixelsCheck = false;
            if (d[4 * (w * i + j) + 1] != 255) pixelsCheck = false;
            if (d[4 * (w * i + j) + 2] != 0) pixelsCheck = false;
            if (d[4 * (w * i + j) + 3] != 255) pixelsCheck = false;
            if(!pixelsCheck) break loopMain1;
        }
    }
    assert_true(pixelsCheck);
    
    ctx.fillStyle = '#0f0';
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);
    
    ctx.fillStyle = '#f00';
    ctx.fillText("fail fail fail fail fail", 5, 35, -1);
    
    var imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
    var w = imageData.width, h = imageData.height, d = imageData.data;
    pixelsCheck = true;
    loopMain2:
    for (var i = 0; i < h; ++i) {
        for (var j = 0; j < w; ++j) {
            if (d[4 * (w * i + j) + 0] != 0)  pixelsCheck = false;
            if (d[4 * (w * i + j) + 1] != 255)  pixelsCheck = false;
            if (d[4 * (w * i + j) + 2] != 0)  pixelsCheck = false;
            if (d[4 * (w * i + j) + 3] != 255)  pixelsCheck = false;
            if(!pixelsCheck) break loopMain2;
        }
    }
    assert_true(pixelsCheck);
    
}, 'Series of tests to ensure that fillText() does not display any text when maxWidth is invalid.');
</script>
</body>

